﻿function IndexViewModel() {
    var self = this;
    self.NavData = [];

    self.NavDataTree = [];
    self.BuildTree = function () {

        self.NavData.forEach(function (x, index) {
            var newItem = {};
            newItem.className = "treeview";
            newItem.ico = x.ico;
            newItem.itemClick = function () {
                alert("");
            }
            if (!(x.parentId) && x.category === "01") {
                newItem.title = x.title;
                if (index === 0)
                    newItem.className = "treeview active";
                newItem.children = [];
                self.NavData.forEach(function (xx) {
                    if (xx.parentId && xx.parentId === x.id && xx.category === "01") {
                        xx.children = [];

                        self.NavData.forEach(function (xxx) {
                            if (xxx.parentId && xxx.parentId === xx.id && xxx.category === "01") {
                                xx.children.push(xxx);
                            }
                        });

                        newItem.children.push(xx);


                    }
                });

                self.NavDataTree.push(newItem);
            }
        });
    }
    self.navItemclick = function (data, item) {
        var $target = $(item.target);
        var url = $(item.target).data("url");
        if (url == null) {
            return false;
        }
        if (url.length === 0 || url === "#") {
            return false;
        }
 
        //$target.parent().siblings().find(".active").removeClass("active");
        //$target.parent().addClass("active");
      
   
        window.app.loadUI(url);
        return false;
    }

}
